<template>
	<view class="my">
		<view class="top">
			<image :src="userinfohelper.avatar?userinfohelper.avatar:'../../static/uni.png'" mode="" class="img"></image>
			<view class="infos">
				<view class="name">
					{{ userinfohelper.username }}
				</view>
				<view class="time">
					共登录{{ times }}次，上次登录{{ time }}
				</view>
			</view>
		</view>
		<view class="banner">
			<navigator :url="'/subPackageHH/OrderSet/OrderSet?item='+userinfohelpers" class="item">
				<BanItem icon="icon-icon_edit" title="预约设置与排期"></BanItem>
			</navigator>
			<navigator url="/subPackageHH/OrderStatic/OrderStatic" class="item">
				<BanItem icon="icon-icon_edit" title="用户预约记录"></BanItem>
			</navigator>
			<view class="item" @click="checkoutCode">
				<BanItem icon="icon-shezhi" title="核销预约"></BanItem>
			</view>		
			
		</view>
		<view class="banner">
			<navigator url="/subPackageHH/login/login?pwd=1" class="item">
				<BanItem icon="icon-zidonghexiao" title="修改登录密码"></BanItem>
			</navigator>
			<!-- <navigator url="/subPackageHH/OrderSet/OrderSet" class="item">
				<BanItem icon="icon-zidonghexiao" title="预览预约页面"></BanItem>
			</navigator> -->
			<view class="item" @click="goPage">
				<BanItem icon="icon-zidonghexiao" title="预览预约页面"></BanItem>
			</view>
		</view>
		<button @click="logout">退出登录</button>
		<!-- <button @click="change">change</button> -->
	</view>
</template>

<script>
	// 引入qrcode库
	// import uQRCode from '../../uni_modules/cc-defineQRCode/components/cc-defineQRCode/common/uqrcode.js'
	import { FindByTelphone, CheckoutCode } from '../../api/index.js'
	import formatTime from '../../utils/FormatTime.js'
	// import {mapState,mapMutations} from 'vuex'
	export default {
		data() {
			return {
				userinfohelper:{}
			};
		},
		onLoad() {
			// console.log(this.$store.commit,'comit')
			// console.log(formatTime(new Date()))
			// console.log(this,this.$store)
			// this.$store.commit('addTimes',1)
			this.userinfohelper = JSON.parse(uni.getStorageSync('userinfohelper')||'')
		},
		computed:{
			// ...mapState(['loginTimes','loginTime']),
			times(){
				return this.$store.state.loginTimes
			},
			time(){
				return this.$store.state.loginTime
			},
			userinfohelpers(){
				return JSON.stringify(this.userinfohelper)
			}
		},
		methods:{
			// ...mapMutations(['addTimes','updateTime']),
			change(){
				// this.$store.commit('addTimes',1)
				// console.log(this.$store.state,'ddd')
				// // this.addTimes(10)
				// console.log(this.$store.state,'hhh')
				// this.$store.commit('updateTime')
			},
			goPage(){
				console.log('gg')
				uni.navigateTo({
					url:'/subPackageHH/PreOrder/PreOrder'
				})
			},
			logout(){
				uni.setStorageSync('userinfohelper','')
				uni.navigateTo({
					url:'/subPackageHH/login/login'
				})
			},
			checkoutCode(){
				// 允许从相机和相册扫码
				uni.scanCode({
					// scanType:'qrCode',//无反应
					scanType:['qrCode'],
					success: async (res)=> {
						// this.qrcodeText = this.username+' '+this.type+' '+this.date+' '+this.myFormatData.username+' '+this.myFormatData.tel
						console.log('条码类型：' + res.scanType);
						console.log('条码内容：' + res.result);
						let results = res.result.split('_')
						console.log(results,'results')
						const { data:res1 } = await FindByTelphone(this.userinfohelper.phone)
						console.log(res1,'res1')
						res1.data.forEach(item=>{
							console.log(item.id,results[3],'ddf')
							if(item.id==results[3]){
								console.log('tttt')
								if(item.status==2){
									return uni.showToast({
										title:'已核销',
										icon:'error'
									})
								}
								if(item.status==3){
									return uni.showToast({
										title:'已过期',
										icon:'error'
									})
								}
								if(item.status==4){
									return uni.showToast({
										title:'系统取消',
										icon:'error'
									})
								}
							// const { data:res } =  CheckoutCode({phone:this.phone,status:2})
							CheckoutCode({phone:this.phone,status:2,id:this.id}).then(res=>{
								console.log(res,'ccc')
								if(res.data.status==0){
									return uni.showToast({
										title:'核销成功',
										icon:'success'
									})
								}
							})
							
						}
						// else{
						// 	console.log('eeee')
						// 	return uni.showToast({
						// 		title:'查询失败未找到',
						// 		icon:'fail'
						// 	})
						// }
						}
						)
						// if(results[0]==res1.data.username){
							
						// 	if(res1.data.status==2){
						// 		return uni.showToast({
						// 			title:'已核销',
						// 			icon:'error'
						// 		})
						// 	}
						// 	if(res1.data.status==3){
						// 		return uni.showToast({
						// 			title:'已过期',
						// 			icon:'error'
						// 		})
						// 	}
						// 	if(res1.data.status==4){
						// 		return uni.showToast({
						// 			title:'系统取消',
						// 			icon:'error'
						// 		})
						// 	}
						// 	const { data:res } = await CheckoutCode({phone:2,status:2})
						// 	console.log(res,'ccc')
						// 	if(res.status==0){
						// 		return uni.showToast({
						// 			title:'核销成功',
						// 			icon:'success'
						// 		})
						// 	}
						// }else{
						// 	return uni.showToast({
						// 		title:'查询失败未找到',
						// 		icon:'fail'
						// 	})
						// }
						}
					
				});
				// 允许从相机和相册扫码
				// uni.scanCode({
				// 	// scanType:'qrCode',//无反应
				// 	scanType:['qrCode'],
				// 	success: async (res)=> {
				// 		// this.qrcodeText = this.username+' '+this.type+' '+this.date+' '+this.myFormatData.username+' '+this.myFormatData.tel
				// 		console.log('条码类型：' + res.scanType);
				// 		console.log('条码内容：' + res.result);
				// 		let results = res.result.split('_')
				// 		console.log(results,'results')
				// 		const { data:res1 } = await FindByTelphone(2)
				// 		console.log(res1,'res1')
				// 		if(results[0]==res1.data.username){
							
				// 			if(res1.data.type==2){
				// 				return uni.showToast({
				// 					title:'已核销',
				// 					icon:'error'
				// 				})
				// 			}
				// 			if(res1.data.type==3){
				// 				return uni.showToast({
				// 					title:'已过期',
				// 					icon:'error'
				// 				})
				// 			}
				// 			if(res1.data.type==4){
				// 				return uni.showToast({
				// 					title:'系统取消',
				// 					icon:'error'
				// 				})
				// 			}
				// 			const { data:res } = await CheckoutCode({tel:2,type:2})
				// 			console.log(res,'ccc')
				// 			if(res.status==0){
				// 				return uni.showToast({
				// 					title:'核销成功',
				// 					icon:'success'
				// 				})
				// 			}
				// 		}else{
				// 			return uni.showToast({
				// 				title:'查询失败未找到',
				// 				icon:'fail'
				// 			})
				// 		}
				// 	}
				// });
			}
		}
	}
</script>

<style lang="scss">
.my{
	width: 100%;
	.top{
		width: 100%;
		height: 120rpx;
		background: #00CDCD;
		color:#fff;
		padding: 20rpx;
		display: flex;
		border-radius: 0 0 0 30rpx;
		// align-items: center;
		.img{
			width: 100rpx;
			height: 100rpx;
			border-radius: 50%;
			margin-right: 15rpx;
		}
		.infos{
			padding-top: 8rpx;
			.name{
				font-weight: bold;
				font-size: 30rpx;
			}
			.time{
				line-height: 60rpx;
				font-size: 28rpx;
			}
		}
	}
	.banner{
		width: 90%;
		background: #fff;
		padding: 15rpx;
		margin: 30rpx auto;
		border-radius: 15rpx;
		display: flex;
		padding-top: 40rpx;
		.item{
			width: 33%;
		}
		
	}
	button{
		width: 90%;
		height: 80rpx;
		line-height: 80rpx;
		background: #00CDCD;
		color: #fff;
		margin-top: 30rpx;
		
	}
}
</style>
